import numpy as np
from armijo import armijo
# input: fun,gfun,Hfun,x0
# output x, val , k

#armijo
# input: fun,rho,
#rho=0.55
#sigma=0.4
#tau=0
##armijo
#mark = 100
#k = 0
#epsilon = 1e-5
#while k < mark :
#    gk= feval(gfun,x0)
#    Hk = feval(Hess,x0)
#    dk = -inv(Hk)\gk
#    if ( norm(gk)< epsilon):
#        break
#    x0 = x0 + dk
#    k=k+1
#
#x = x0
#val = feval(func,x)


def revisenum(fun,gfun,Hfun,x0,k,eps,maxk=100):
    gk= gfun(x0)
    muk = np.linalg.norm(gk)**(1+tau)
    Hk = Hfun(x0)
    dk = -(Hk+muk*np.linalg.eye(n))\gk
    if np.linalg.norm(gk) < eps or k >= maxk:
        return x0, fun(x0), k
    step = armijo(x0,dk,gk,fun,rho=0.55,sigma=0.4,m=0,maxm=20)
    return(fun,gfun,Hfun,x0+step,k+1,eps,maxk)
